<div class="amp-content">
  <h3 class="amp-header"><?php echo $action_title; ?></h3>

  <div class="amp-content">
    <?php if ($path || ! empty($filters) || (! empty($pager) && $pager->getTotalPages() > 1)) { ?>
    <form action="<?php echo s::makeUrl($route) ?>" method="get">
      <span class="toolbar-container">
        <ul class="toolbar">
          <li class="toolbar-item"><a href="<?php echo s::makeUrl($route, array($parent => $path[count($path) - 1][$parent])) ?>">&uarr; up</a></li>

          <li class="toolbar-item">
            <a href="<?php echo s::makeUrl($route, array($parent => 0)) ?>">Root</a>

            <?php if ($path) {
              $c = count($path);
              foreach ($path as $_parent) { ?>
                &ndash;
                <?php if (--$c > 0) { ?>
                  <a href="<?php echo s::makeUrl($route, array($parent => $_parent[$pk])) ?>"><?php echo $_parent[$label] ?></a>
                <?php } else {
                  echo $_parent[$label];
                }
              }
            }
            ?>
          </li>

          <?php if (! empty($filters)) { ?>
          <li class="toolbar-item">Filter</li>

          <?php foreach ($filters as $filter) { ?>
          <li class="toolbar-item"><?php echo $filter->render() ?></li>
          <?php } ?>

          <li class="toolbar-item"><input type="submit" value="Ok"/></li>
          <?php } ?>

          <?php if (! empty($pager)) { ?>
            <?php echo $this->pager->show($pager); ?>
          <?php } ?>
        </ul>
        <div style="clear:both;"></div>
      </span>
    </form>
    <?php } ?>

    <form action="<?php echo s::makeUrl($route, array('action' => 'bulk')) ?>" method="post" class="wrapper">
      <div class="media-gallery">
        <ul class="tiled-list">
          <?php while ($obj = $data->next()) { ?>
          <li class="list-item">
            <a href="<?php echo $obj->image_src ?>" class="lightbox thumb" alt="<?php echo $obj->image_caption ?>"
              title="<?php echo $obj->image_caption ?>"/><img src="<?php echo $obj->thumb_src ?>"/></a>

            <span class="no-label actions">
              <input type="checkbox" class="row-check" name="<?php echo $pk ?>[]" value="<?php echo $obj->$pk ?>"/>
              <?php
              echo $this->menu_item->show(array('icon' => 'view', 'label' => 'View', 'route' => $route, 'params' => array('action' => 'view', $pk => $obj->$pk)));
              echo $this->menu_item->show(array('icon' => 'edit', 'label' => 'Edit', 'route' => $route, 'params' => array('action' => 'edit', $pk => $obj->$pk)));
              echo $this->menu_item->show(array('label' => 'Delete', 'icon' => 'delete', 'route' => $route,
                'params' => array('action' => 'delete', $pk => $obj->$pk), 'linkParams' => array('onclick' => "return confirm('Do you confirm this action?');")));
              ?>
            </span>
          </li>
          <?php } ?>
        </ul>
      </div>

      <span class="toolbar-container">
        <ul class="toolbar">
          <li class="toolbar-item">
            <select name="bulk_action">
              <option value="">Bulk actions</option>
              <option value="view">View</option>
              <option value="delete">Delete</option>
            </select>
            <input type="submit" value="Ok"/>
          </li>

          <li class="toolbar-item no-label">
            Selecionar
            <a href="javascript:" onclick="selectAll();"><span class="icon icon-select-all"></span><span class="label">Select all</span></a>
            <a href="javascript:" onclick="selectNone();"><span class="icon icon-select-none"></span><span class="label">Select none</span></a>
            <a href="javascript:" onclick="selectInvert();"><span class="icon icon-select-invert"></span><span class="label">Select invert</span></a>
          </li>

          <?php if (! empty($pager)) { ?>
            <?php echo $this->pager->show($pager); ?>
          <?php } ?>
        </ul>

        <div style="clear:both;"></div>
      </span>
    </form>
  </div>

  <input id="file_upload" name="file_upload" type="file"/>
  <span id="file_uploadUploader" style="display:block;width:120px;height:30px;overflow:hidden;"></span>

  <?php $config = s::config() ?>
  <?php echo $this->html->css($config['theme_url'] . '/uploadify/uploadify.css') ?>
  <?php echo $this->javascript->link('swfobject.js') ?>
  <?php echo $this->javascript->link($config['theme_url'] . '/uploadify/jquery.uploadify.v2.1.4.min.js') ?>

  <script>
  $(document).ready(function() {
    $('#file_upload').uploadify({
      uploader: '<?php echo $config['theme_url'] ?>/uploadify/uploadify.swf',

      script: '<?php echo $uploadScript ?>',
      scriptData: <?php echo $uploadScriptData ?>,
      method: 'GET',

      cancelImg: '<?php echo $config['theme_url'] ?>/uploadify/cancel.png',
      multi: true,
      removeCompleted: true,
      auto: true,

      onError: function(event, ID, fileObj, errorObj) {
        alert(errorObj.info);
      },

      onComplete: function(event, ID, fileObj, response, data) {
        //alert(response);
      }
    });
  });
  </script>

  <style>
  .media-gallery .list-item {
    position:relative;
    width:100px;
    height:100px;
    margin-right:10px;
    margin-bottom:10px;
    border:1px solid #ccc;
  }

  .media-gallery .list-item .actions {
    position:absolute;
    top:5px;
    left:5px;
  }

  .media-gallery .list-item .actions * {
    line-height:20px;
    vertical-align:middle;
  }
  </style>

  <script>
  function selectAll() {
    $('.row-check').attr('checked', 'checked');
  };

  function selectNone() {
    $('.row-check').removeAttr('checked');
  };

  function selectInvert() {
    var on = $('.row-check:checked');
    $('.row-check').attr('checked', 'checked');
    on.removeAttr('checked');
  };

  $(document).ready(function() {
    $('.media-gallery .list-item').mouseenter(function() {
      $(this).find('.actions a').fadeIn('fast');
    }).mouseleave(function() {
      $(this).find('.actions a').fadeOut('fast');
    }).find('.actions a').hide();

    <?php if ($sortable) { ?>
    $('.media-gallery ul').sortable({
      forcePlaceholderSize: true,

      stop: function(event, ui) {
        var url = '<?php echo s::makeUrl($route, array('formAction' => 'sort')) ?>';

        var data = {
          sortIndex: ui.item.index() + 1,
          <?php echo $pk ?>: ui.item.find('.row-check').val()
        };

        $.get(url, data);
      }
    });
    <?php } ?>
  });
  </script>
</div>
